<template>
	<view class="container">
		<!-- 地址 -->
		<selectAddress @changeAddress="changeAddress"></selectAddress>
		
		
		<view class="u-p-30 u-type-white-bg u-radius-10 u-m-tb-20">
			<view class="u-font-bold">套餐信息</view>
			<u-line color="#Ffffff" margin="10rpx 0"></u-line>
			<view class="u-flex">
				<u-image width="195" height="185" :src="detail.image" ></u-image>
				<view class="u-m-l-25">
					<view class="u-font-30 u-font-bold">{{detail.goods_name}}</view>
					<view class="u-font-24 u-m-t-20 listItem u-w-400 ">
						<view class="u-line-1" v-for="(item,index) in detail.param" :key="index">{{item}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="u-flex u-col-center u-row-between u-p-30 u-type-white-bg u-radius-10 u-m-tb-20">
			<view>
				订单备注
			</view>
			<u-input v-model="remark" type="text" placeholder="请在这里留下你的留言" height="40" input-align="right"></u-input>
		</view>
		<u-gap height="150"></u-gap>
		<view class="submit-btn safe-area-inset-bottom">
			<view class="u-p-30">
				<u-button type="success" shape="circle" :custom-style="{background:'#009476'}" @click="submitBtn">确认下单</u-button>
			</view>
		</view>
		
		<u-popup v-model="popupFlag" mode="center" border-radius="10">
			<view class="u-w-580 u-type-white-bg u-p-30">
				<view class="u-font-26 u-text-center">温馨提示</view>
				<u-line color="#fff" margin="40rpx"></u-line>
				<view class="u-font-42 u-font-bold u-text-center">物品由两个包裹寄出～</view>
				<u-line color="#fff" margin="40rpx"></u-line>
				<u-button type="success" shape="circle" :custom-style="{background:'#009476',width: '330rpx',height: '70rpx',fontSize: '26rpx'}" @click="popupFlag = false">我知道了</u-button>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import selectAddress from './components/selectAddress.vue'
	export default {
		components: {
			selectAddress
		},
		data() {
			return {
				popupFlag: false,
				detail: {},
				address_id: '',
				remark: ''
			}
		},

		onLoad({id}) {
			this.getDetail(id)
		},
		methods: {
			// 确认下单
			submitBtn(){
				if(this.address_id == '') return this.$u.toast('请选择地址')
				this.$u.api.addShopOrder({address_id: this.address_id,goods_id:this.detail.id,remark: this.remark}).then(res => {
					this.$u.toast(res.msg)
					setTimeout(() => uni.redirectTo({
						url: '/pages/order/index?current=1'
					}) ,1500)
				}).catch(err => {
					this.$u.toast(err.msg)
				})
			},
			// 选择地址
			changeAddress(id){
				this.popupFlag = true
				this.address_id = id
			},
			getDetail(id){
				this.$u.api.getGoodsInfo({
					id
				}).then(res => {
					this.detail = res.data
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		padding: 30rpx;
	}
	
	.listItem{
		color: #666666;
		line-height: 36rpx;
	}
</style>